home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Programmation / Gooey1.3.1 / C Templates / mmAlert.c < prev    next >
Text File  |  1994-04-17  |  12KB  |  339 lines

  1. $$Loop Alerts
  2. $$Message MM Alert, mm:mmA_$Worksheet.name$.c
  3.  
  4. $$File mm:mmA_$Worksheet.name$.c
  5. /*  mmA_$Worksheet.name$                                 Handle this alert */
  6. /*  $CopyRight$ */
  7.  
  8. /*    File name:  mmA_$Worksheet.name$
  9.     Function:  Handle this alert.
  10. $$if Alert.Stop
  11.     This is a STOP alert, it is used to inform the user that data is about to be lost.
  12.     It is also used for fatal type errors and tells the user about the error.
  13. $$endif
  14. $$if Alert.Note
  15.     This is a NOTE alert, it is used to inform the user of some general information.
  16.     This alert is not used if there is a possibility of losing any data.
  17. $$endif
  18. $$if Alert.Caution
  19.     This is a CAUTION alert, it is used to inform the user that if the current path
  20.     is taken then data may be lost.  The user can change the present course and
  21.     save the data.  This is the type of alert used to tell the user that he needs to
  22.     save the data before going on.
  23. $$endif
  24.  
  25.     This alert is called when:
  26.  
  27.     The choices in this alert allow for:
  28.         
  29.     History: $Date$ Original by $Author$
  30.  
  31. */
  32.  
  33. #include "mmCommon$Prototype.name$.h"    /* Common */
  34. #include "Common$Prototype.name$.h"        /* Common */
  35.  
  36. #include "$Worksheet.name$.h"            /* Users specific file */
  37.  
  38. #pragma segment Alerts
  39.  
  40. /* Prototype for filter routine */
  41. static pascal Boolean MyFilter (DialogPtr theDialog,EventRecord *theEvent,short *itemHit);
  42.  
  43. /* ======================================================= */
  44.  
  45. /* Routine: MyFilter */
  46. /* Purpose: Filter routine, also used for initial setup of dimmed states */
  47.  
  48. static pascal Boolean MyFilter (DialogPtr theDialog,EventRecord *theEvent,short *itemHit)
  49. {
  50. Boolean            FilterValue;                            /* Temporary return value */
  51. Rect            tempRect;                                /* Temporary rectangle */
  52. short            DType;                                    /* Type of dialog item */
  53. Handle            DItem;                                    /* Handle to the dialog item */
  54. ControlHandle    CItem;                                    /* Control handle */
  55. short            chCode;                                    /* Key entered */
  56. long            LTemp,LTemp2;                            /* Used for time delay and HotSpot definitions */
  57. $$if Worksheet.HasControls
  58. RGBColor        Saved_ForeColor;                        /* Place to save colors */
  59. RGBColor        Saved_BackColor;                        /* Place to save colors */
  60. RGBColor        DrawingColor;                            /* Place to make colors */
  61. $$endif Worksheet.HasControls
  62.  
  63.  
  64. FilterValue = false;
  65. if (Rec_$Worksheet.name$.FirstTime)                        /* Make all controls and do lines and rects */
  66.     {
  67. $$Loop Control.type = Button
  68.     SetupNormalControl(theDialog,ResA_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,0);
  69.     $$if Control.Default
  70.     /* This is the default selection, when RETURN is pressed. */
  71.     HiliteDefaultButton(theDialog,ResA_$Control.name$);
  72.  
  73.     $$endif Control.Default
  74. $$EndLoop Control.type
  75. $$Loop Control.type = StaticText
  76. $$if Control.SpecialText
  77.     /* Draw static text, $Control.FullName$ */
  78.     $$if Control.TextColor ! Black
  79.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  80.         {
  81.         DrawingColor.red = 0x$Control.RedTextColor$;
  82.         DrawingColor.green = 0x$Control.GreenTextColor$;
  83.         DrawingColor.blue = 0x$Control.BlueTextColor$;
  84.         RGBForeColor(&DrawingColor);                    /* Set the fore color */
  85.         RGBBackColor(&Saved_BackColor);                    /* Set the back color */
  86.         }
  87.     $$endif Control.TextColor
  88.     $$if Control.MultipleLine
  89.     SetRect(&tempRect,$Control.LeftPosition$,$Control.TopPosition$,$Control.RightPosition$,$Control.BottomPosition$);
  90.     DrawStaticTextBox(sResA_$Control.name$,&tempRect,$Control.TextAlignment$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  91.     $$endif Control.MultipleLine
  92.     $$if Control.SingleLine
  93.     DrawStaticLine(sResA_$Control.name$,$Control.LeftPosition$,$Control.TopPosition$,$Control.TextSize$,$Control.TextFont$,$Control.TextStyle$);
  94.     $$endif Control.SingleLine
  95.     $$if Control.TextColor ! Black
  96.     if (Has.ColorQD)                                        /* See if color QuickDraw is around */
  97.         {
  98.         RGBForeColor(&Black_ForeColor);                    /* Set the fore color */
  99.         RGBBackColor(&White_BackColor);                    /* Set the back color */
  100.         }
  101.     $$endif Control.TextColor
  102.  
  103. $$endif
  104. $$EndLoop
  105. $$Loop Control.type = Icon
  106.     $$if Control.NonGraphic
  107.     /* Draw an Icon button */
  108.     SetupIconSicn(theDialog,ResA_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  109.         ResA_N_$Control.name$,ResA_H_$Control.name$);
  110.  
  111.     $$endif Control.NonGraphic
  112. $$EndLoop
  113. $$Loop Control.type = Picture
  114.     $$if Control.NonGraphic
  115.     /* Draw a picture, $Control.FullName$ */
  116.     LTemp = ResA_N_$Control.name$;                        /* Picture ID and resize flag */
  117.     $$if Control.ClipPicture
  118.     LTemp = 0x00010000 | LTemp;
  119.     $$endif Control.ClipPicture
  120.     SetupTheItem(theDialog,ResA_$Control.name$,true,true,$Control.Active$,false,&tempRect,LTemp,0);/* Setup the Picture button */
  121.  
  122.     $$endif Control.NonGraphic
  123. $$EndLoop
  124. $$Loop Control.type = UButton
  125.     SetupPlugin(theDialog,ResA_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  126.         ResA_N_$Control.name$,ResA_H_$Control.name$,sResA_$Control.name$);
  127.     
  128. $$EndLoop
  129. $$Loop Control.type = Line
  130.     /* Draw a line, $Control.FullName$ */
  131.     $$if Control.GrayLine
  132.     PenPat(&qd.gray);                                        /* Set the gray pen pattern */
  133.     $$endif Control.GrayLine
  134.     $$if Control.LineWidth ! 1
  135.     PenSize($Control.LineWidth$,$Control.LineWidth$);
  136.     $$endif Control.LineWidth
  137.     MoveTo($Control.LeftPosition$,$Control.TopPosition$);        /* Horz,vert, Move to starting position */
  138.     LineTo($Control.RightPosition$,$Control.BottomPosition$);    /* Horz,vert, Draw to the ending position */
  139.     $$if Control.LineWidth ! 1
  140.     PenSize(1,1);
  141.     $$endif Control.LineWidth
  142.     $$if Control.GrayLine
  143.     PenPat(&qd.black);                                        /*  Back to default pen pattern  */
  144.     $$endif Control.GrayLine
  145.  
  146. $$EndLoop
  147. $$Loop Control.type = HotRect
  148.     /* Draw a Hotspot or Rectangle, $Control.FullName$ */
  149.     SetupHotSpot(theDialog,ResA_$Control.name$,$Control.MakeHotSpot$,$Control.LineWidth$,
  150.         $Control.ShadowWidth$,sResA_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$);
  151.  
  152. $$EndLoop
  153. $$Loop Control.type = Sicn
  154.     /* Draw an Sicn */
  155. $$if Control.Graphic
  156.     SetupIconSicn(theDialog,ResA_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  157.         ResA_N_$Control.name$,ResA_N_$Control.name$);
  158. $$endif Control.Graphic
  159. $$if Control.NonGraphic
  160.     SetupIconSicn(theDialog,ResA_$Control.name$,Rec_$Worksheet.name$.Enable_$Control.name$,
  161.         ResA_N_$Control.name$,ResA_H_$Control.name$);
  162. $$endif Control.NonGraphic
  163.  
  164. $$EndLoop
  165.     Rec_$Worksheet.name$.FirstTime = false;                /* Not first time anymore */
  166.     }
  167.  
  168. FilterValue = Filter_$Worksheet.name$(theDialog, theEvent, itemHit);/* Call the user routine */
  169.  
  170. CheckKeysInDialog(theDialog,&FilterValue,theEvent,itemHit);
  171.  
  172. return(FilterValue);
  173. }
  174.  
  175. /* ======================================================= */
  176.  
  177. void InitA_$Worksheet.name$(void)
  178. {
  179.  
  180.  
  181.     $$Loop Control.type = Button
  182. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;
  183.     $$EndLoop Control.type
  184.     $$Loop Control.type = Icon
  185. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;
  186.     $$EndLoop
  187.     $$Loop Control.type = Picture
  188.     $$if Control.NonGraphic
  189. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;
  190.     $$endif Control.NonGraphic
  191.     $$EndLoop
  192.     $$Loop Control.type = UButton
  193. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;
  194.     $$EndLoop
  195.     $$Loop Control.type = HotRect
  196. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;
  197.     $$EndLoop
  198.     $$Loop Control.type = Sicn
  199. Rec_$Worksheet.name$.Enable_$Control.name$ = $Control.Active$;
  200.     $$EndLoop
  201.  
  202. A_Init_$Worksheet.name$();                                /* Tell the user routine */
  203. }
  204.  
  205. /* ======================================================= */
  206.  
  207. void PA_$Worksheet.name$(void)
  208. {
  209. short        itemHit;                                /* Get the selection ID in here */
  210. AlertTHndl    AlertResHandle;                            /* Resource handle for Alert */
  211. Rect        tempRect;                                /* Temp rect for moving the alert */
  212. #if defined(powerc) || defined(__powerc)
  213. ModalFilterUPP    theFilter;
  214. #endif
  215.  
  216.  
  217. AlertResHandle = (AlertTHndl)GetResource('ALRT',ResA_$Worksheet.name$);/* Get the Alerts resource template handle */
  218. HLock((Handle)AlertResHandle);                        /* Lock the resource down while we use it */
  219. $$if Worksheet.Center
  220. tempRect = (*AlertResHandle)->boundsRect;            /* Get the alerts position and size */
  221. $$if Worksheet.CenterHorz
  222. tempRect.left = ((screenRect.bounds.right - screenRect.bounds.left) - (tempRect.right - tempRect.left)) / 2;    /* Center Horz */
  223. $$endif Worksheet.CenterHorz
  224. $$if Worksheet.CenterVert
  225. tempRect.top = ((screenRect.bounds.bottom - screenRect.bounds.top) - (tempRect.bottom - tempRect.top)) / 3;    /* 1/3 vert */
  226. $$endif Worksheet.CenterVert
  227. tempRect.bottom = tempRect.top + ((*AlertResHandle)->boundsRect.bottom - (*AlertResHandle)->boundsRect.top);
  228. tempRect.right = tempRect.left + ((*AlertResHandle)->boundsRect.right - (*AlertResHandle)->boundsRect.left);
  229. (*AlertResHandle)->boundsRect = tempRect;            /* Place the centered position back in the template */
  230. $$endif
  231.  
  232. Rec_$Worksheet.name$.FirstTime = TRUE;                /* Set the flag for the filter proc */
  233. $$Link    Worksheet.Open
  234.  
  235. /* Let the OS handle the Alert and wait for a result to be returned */
  236. #if defined(powerc) || defined(__powerc)
  237. theFilter = NewModalFilterProc(MyFilter);
  238. #endif
  239. $$if Alert.Stop
  240. #if defined(powerc) || defined(__powerc)
  241. itemHit = StopAlert(ResA_$Worksheet.name$,theFilter);        /* Bring in the alert resource */
  242. #else
  243. itemHit = StopAlert(ResA_$Worksheet.name$,(ModalFilterProcPtr)&MyFilter);/* Bring in the alert resource */
  244. #endif
  245. $$endif
  246. $$if Alert.Note
  247. #if defined(powerc) || defined(__powerc)
  248. itemHit = NoteAlert(ResA_$Worksheet.name$,theFilter);        /* Bring in the alert resource */
  249. #else
  250. itemHit = NoteAlert(ResA_$Worksheet.name$,(ModalFilterProcPtr)&MyFilter);/* Bring in the alert resource */
  251. #endif
  252. $$endif
  253. $$if Alert.Caution
  254. #if defined(powerc) || defined(__powerc)
  255. itemHit = CautionAlert(ResA_$Worksheet.name$,theFilter);        /* Bring in the alert resource */
  256. #else
  257. itemHit = CautionAlert(ResA_$Worksheet.name$,(ModalFilterProcPtr)&MyFilter);/* Bring in the alert resource */
  258. #endif
  259. $$endif
  260. HUnlock((Handle)AlertResHandle);                    /* Release the alert handle to float */
  261.  
  262. $$Loop Control.type = Button
  263.     $$if Control.HasLinks
  264.     $$if Control.Default
  265. /* This is the default selection, when RETURN is pressed. */
  266.     $$endif
  267. if (ResA_$Control.name$ == itemHit)                /* $Control.FullName$,See if this control was selected */
  268.     {
  269.     $$Link    Control.Select
  270.     }
  271.  
  272.     $$endif
  273. $$EndLoop Control.type
  274. $$Loop Control.type = Icon
  275.     $$if Control.HasLinks
  276.     $$if Control.NonGraphic
  277. if (ResA_$Control.name$ == itemHit)                /* $Control.FullName$,See if this control was selected */
  278.     {
  279.     $$Link    Control.Select
  280.     }
  281.  
  282.     $$endif Control.NonGraphic
  283.     $$endif
  284. $$EndLoop
  285. $$Loop Control.type = Picture
  286.     $$if Control.HasLinks
  287.     $$if Control.NonGraphic
  288. if (ResA_$Control.name$ == itemHit)                /* $Control.FullName$,See if this control was selected */
  289.     {
  290.     $$Link    Control.Select
  291.     }
  292.  
  293.     $$endif Control.NonGraphic
  294.     $$endif
  295. $$EndLoop
  296. $$Loop Control.type = UButton
  297.     $$if Control.HasLinks
  298. if (ResA_$Control.name$ == itemHit)                /* $Control.FullName$,See if this control was selected */
  299.     {
  300.     $$Link    Control.Select
  301.     }
  302.  
  303.     $$endif
  304. $$EndLoop
  305. $$Loop Control.type = HotRect
  306.     $$if Control.HasLinks
  307.     $$if Control.HotSpot
  308. if (ResA_$Control.name$ == itemHit)                /* $Control.FullName$,See if this control was selected */
  309.     {
  310.     $$Link    Control.Select
  311.     }
  312.  
  313.     $$endif Control.HotSpot
  314.     $$endif
  315. $$EndLoop
  316. $$Loop Control.type = Sicn
  317.     $$if Control.HasLinks
  318.     $$if Control.NonGraphic
  319. if (ResA_$Control.name$ == itemHit)                /* $Control.FullName$,See if this control was selected */
  320.     {
  321.     $$Link    Control.Select
  322.     }
  323.  
  324.     $$endif Control.NonGraphic
  325.     $$endif
  326. $$EndLoop
  327.  
  328. A_Hit_$Worksheet.name$(itemHit);                        /* Tell the user routine which item was selected */
  329.  
  330. $$Link    Worksheet.Close
  331. }
  332.  
  333. /* ======================================================= */
  334. /* ======================================================= */
  335. $$CloseFile
  336. $$EndLoop
  337.  
  338.  
  339.